<?php
/**
 * QQAS - share your knowledge to the world!
 * 
 * @author		xiaochong0302 <xiaochong0302@gmail.com>
 * @copyright	Copyright (c) 2011, Koogua Studio.
 * @license		http://www.qqas.org/user_guide/license.html
 * @link		http://www.qqas.org
 * @since		Version 1.0
 * @filesource
 */
 
// ------------------------------------------------------------------------

/**
 * 各类邮件通知。本系统没有直接调用发送通知, 而以"异步"的方式发送邮件通知以避免等待时间过长。
 *
 * @category  Home
 */
class NotificationAction extends HomeAction 
{

	
	protected $Mailer;
	
    
	//初始化
	function _initialize()
	{
		parent::_initialize();
		$this->Mailer = A('Mailer');
	}
	
	
	//注册确认邮件
	public function confirmAccount()
    {
    	$userID = intval($_GET['uid']);
    	$this->Mailer->confirmAccount($userID);
    }

    
    //邮件地址重验证
	public function validateEmail()
    {
    	$userID = intval($_GET['uid']);
    	$email  = trim($_GET['email']);
    	$this->Mailer->validateEmail($userID, $email);
    }

    
	//注册欢迎邮件
	public function welcomeMessage()
    {
    	$userID = intval($_GET['uid']);
    	$this->Mailer->welcomeMessage($userID);
    }

    
    //新粉丝通知邮件
    public function newFollowerAlert()
    {
    	$sourceID = intval($_GET['source_id']);
    	$targetID = intval($_GET['target_id']);
    	$this->Mailer->newFollowerAlert($sourceID, $targetID);
    }

    
	//新答案通知邮件
	public function newAnswerAlert()
    {
    	$ansID = intval($_GET['aid']);
    	$this->Mailer->newAnswerAlert($ansID);
    }

    
    //答案新评论通知邮件
	public function newAnswerCommentAlert()
    {
    	$cmtID = intval($_GET['cid']);
    	$this->Mailer->newAnswerCommentAlert($cmtID);
    }

    
    //票选最佳答案通知邮件
	public function votedAsBestAnswerAlert()
    {
    	$qstID = intval($_GET['qid']);
    	$this->Mailer->votedAsBestAnswerAlert($qstID);
    }

    
    //当选最佳答案通知邮件
	public function selectedAsBestAnswerAlert()
    {
    	$ansID = intval($_GET['aid']);
    	$this->Mailer->selectedAsBestAnswerAlert($ansID);
    }

    
    //关闭过期问题通知
    public function closeExpiredQuestionAlert()
    {
    	$qstID = intval($_GET['qid']);
    	$this->Mailer->closeExpiredQuestionAlert($qstID);
    }

    
    //关闭未解决问题通知
    public function closeUnresolvedQuestionAlert()
    {
    	$qstID = intval($_GET['qid']);
    	$this->Mailer->closeUnresolvedQuestionAlert($qstID);
    }
    
    
    //新入团申请通知
    public function newTeammateAlert()
    {
    	$userID = intval($_GET['uid']);
    	$teamID = intval($_GET['tid']);
    	$this->Mailer->newTeamMateAlert($userID, $teamID);
    }

    
    //生日祝福邮件
    public function birthdayWishes()
    {
        $userID = intval($_GET['uid']);
        $this->Mailer->birthdayWishes($userID);
    }
    
    
    //退订答案通知
    public function stopAnswerAlert()
    {
    	$Question = D('Question');
    	
    	list($userID, $qstID) = explode("\t", kg_auth_code($_GET['auth'], 'decode')); 
    	
		$question = $Question->find($qstID);
    	if (empty($question) || $userID != $question['poster_id'])
    	{
    		$this->error(L('unsubscribe_link_invalid'));
    	}
    	else 
    	{
    		$where = array('question_id' => $qstID);
    		$Question->where($where)->setField('new_answer_alert', 0);
    		$this->assign('jumpUrl', $this->_global['site_url']);
    		$this->success(L('answer_alert_unsubscribed'));
    	}
    }
    
    
    //退订评论通知
    public function stopCommentAlert()
    {
    	$Answer = D('Answer');
    	
    	list($userID, $ansID) = explode("\t", kg_auth_code($_GET['auth'], 'decode')); 
    	
    	$answer = $Answer->find($ansID);
    	if (empty($answer) || $userID != $answer['poster_id'])
    	{
    		$this->error(L('unsubscribe_link_invalid'));
    	}
    	else 
    	{
    		$where = array('answer_id' => $ansID);
    		$Answer->where($where)->setField('new_comment_alert', 0);
    		$this->success(L('comment_alert_unsubscribed'));
    	}
    }
    
}
// End  Class

/* End of file NotificationAction.class.php */
/* Location: ./App/Lib/Action/Home/NotificationAction.class.php */